<template>
  <div>
    <BasicTable @register="registerTable">
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
    <ThirdCheckUseDrawer @register="registerThirdCheckUseDrawer"></ThirdCheckUseDrawer>
  </div>
</template>
<script lang="ts" setup name="thirdCheck">
import { ActionItem, BasicTable, TableAction } from '@apps/antd-admin/src/components/Table';
import { useDrawer } from '@apps/antd-admin/src/components/drawer';
import { useBaseTable } from '@apps/antd-admin/src/hooks';
import { columns, searchFormSchema } from './data/data';
import { useMessage } from '@apps/antd-admin/src/hooks/web/useMessage';
import ThirdCheckUseDrawer from './components/ThirdCheckUseDrawer.vue';
import { Api } from './data/api';

const [registerDrawer, { openDrawer }] = useDrawer();
const { prefixCls, tableContext, handleDelete, handleSuccess, handlePost, handleBatchDelete } = useBaseTable({
  designScope: 'thirdCheck-template',
  tableProps: {
    //表格标题
    title: '三方核验记录',
    //主键字段
    rowKey: 'thirdCheckId',
    //列表接口
    listUrl: Api.page,
    //列定义
    columns,
    //查询表单配置
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
      showExportButton: true,
    },
    //操作列配置
    actionColumn: {
      width: 120,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right',
    },
  },
});
const { createMessage, createConfirm } = useMessage();
const [registerTable, { reload }, { rowSelection, hasSelectedRows }] = tableContext;

const [registerThirdCheckUseDrawer, { openDrawer: openThirdCheckUseDrawer }] = useDrawer();

/**
 * 行内操作栏
 */
function getTableAction(record): ActionItem[] {
  return [
    {
      label: '查看使用人',
      onClick: handlerLookUseUser.bind(null, record),
    },
  ];
}

function handlerLookUseUser(record) {
  openThirdCheckUseDrawer(true, {
    record,
    isUpdate: false,
  });
}
</script>
